package com.hsr.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsr.web.dto.ArticleQuery;
import com.hsr.web.entity.TArticle;
import com.hsr.web.mapper.TArticleMapper;
import com.hsr.web.service.ITArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tb
 * @since 2022-04-02
 */
@Service
public class TArticleServiceImpl extends ServiceImpl<TArticleMapper, TArticle> implements ITArticleService {

    @Override
    public IPage<TArticle> getList(ArticleQuery query) {
        LambdaQueryWrapper<TArticle> wrapper= Wrappers.lambdaQuery();
        wrapper.like(StringUtils.hasLength(query.getArticleTitle()),TArticle::getArticleTitle,query.getArticleTitle())
                .eq(null!=query.getArticleType(),TArticle::getArticleType,query.getArticleType())
                .eq(null!=query.getArticleState(),TArticle::getArticleState,query.getArticleState())
                .orderByDesc(TArticle::getCreateTime);
        return page(new Page<>(query.getPage(),query.getSize()),wrapper);
    }
}
